package com.project.controller;

import com.framework.core.result.APIObjResponse;
import com.framework.core.result.BasePage;
import com.project.base.BaseController;
import com.project.biz.CmsCapitalFlowBiz;
import com.project.common.model.UserInfo;
import com.project.pojo.dto.CmsCapitalFlowDTO;
import com.project.pojo.dto.FundStatisticsDTO;
import com.project.pojo.model.AddSystemUpperScoreModel;
import com.project.pojo.model.GetCmsCapitalFlowModel;
import com.project.pojo.model.UpdateDeductionModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @Description: 资金流水
 * @Author: zhuchi
 * @CreateDate: 2020/11/18 23:19
 * @Version: 1.0
 */
@Api(value = "CmsCapitalFlowController", description = "资金流水")
@RestController
@RequestMapping("/flow")
@Slf4j
public class CmsCapitalFlowController extends BaseController {

    /**
     * 资金流水业务层接口类
     */
    @Autowired
    private CmsCapitalFlowBiz capitalFlowBiz;

    /**
     * 按条件查询资金流水
     * @return
     */
    @ApiOperation(value = "按条件查询资金流水", httpMethod = "POST")
    @PostMapping(value = "/getCapitalFlow")
    public APIObjResponse<BasePage<CmsCapitalFlowDTO>> getCapitalFlow(@RequestBody GetCmsCapitalFlowModel getCmsCapitalFlowModel){
        BasePage<CmsCapitalFlowDTO> basePage = this.capitalFlowBiz.getCapitalFlow(getCmsCapitalFlowModel);
        return APIObjResponse.success("查询成功", basePage);
    }

    /**
     * 获取个人收入、支出明细
     * @return
     */
    @ApiOperation(value = "获取个人收入、支出明细", httpMethod = "POST")
    @PostMapping(value = "/getMyCapitalFlow")
    public APIObjResponse<BasePage<CmsCapitalFlowDTO>> getMyCapitalFlow(@RequestBody GetCmsCapitalFlowModel getCmsCapitalFlowModel){
        UserInfo userInfo = super.getLoginUser();
        getCmsCapitalFlowModel.setBaseUserId(userInfo.getBaseUserId());
        BasePage<CmsCapitalFlowDTO> basePage = this.capitalFlowBiz.getCapitalFlow(getCmsCapitalFlowModel);
        return APIObjResponse.success("查询成功", basePage);
    }

    /**
     * 系统上分
     * @return
     */
    @ApiOperation(value = "系统上分", httpMethod = "POST")
    @PostMapping(value = "/addSystemUpperScore")
    public APIObjResponse<Integer> addSystemUpperScore(@Validated @RequestBody AddSystemUpperScoreModel addSystemUpperScoreModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.capitalFlowBiz.addSystemUpperScore(addSystemUpperScoreModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 系统扣款
     * @return
     */
    @ApiOperation(value = "系统扣款", httpMethod = "POST")
    @PostMapping(value = "/updateDeduction")
    public APIObjResponse<Integer> updateDeduction(@Validated @RequestBody UpdateDeductionModel updateDeductionModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.capitalFlowBiz.updateDeduction(updateDeductionModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 获取后台统计信息
     * @return
     */
    @ApiOperation(value = "获取后台统计信息", httpMethod = "GET")
    @GetMapping(value = "/getFundStatistics")
    public APIObjResponse<FundStatisticsDTO> getFundStatistics(){
        FundStatisticsDTO result = this.capitalFlowBiz.getFundStatistics();
        return APIObjResponse.success("查询成功", result);
    }

}
